package com.ys.shop.control;

import com.ys.shop.dao.GoodDAOImp;
import com.ys.shop.dao.GoodTypeDAOImp;
import com.ys.shop.dao.IDAO;
import com.ys.shop.vo.GoodType;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "GoodServlet")
public class GoodServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter printWriter=response.getWriter();
//        printWriter.print("qwer");
        //显示所有商品     dao获取所有商品   转到显示所有商品的页面
        IDAO dao=new GoodDAOImp();
        IDAO dao1=new GoodTypeDAOImp();
        List listgood=null;
        List listgoodtype=null;
        try {
            listgood=dao.getAll();
            listgoodtype=dao1.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("goodall",listgood);
        request.setAttribute("goodtypeall",listgoodtype);

        request.getRequestDispatcher("/Index.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
